/*
 * Copyright (c) 2017-2021, Lindenis Tech. Ltd.
 * All rights reserved.
 *
 * File:
 *
 * Description: reliable data transfer
 *
 * Author:
 *      xiaoshujun@lindeni.com
 *
 * Create Date:
 *      2021/03/16
 *
 * History:
 *
 */

#ifndef __LIND_SINK_H__
#define __LIND_SINK_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include "lindnet.h"

#include "lindcomponent.h"

typedef enum _lindsink_type_e
{
    LINDSINK_RTP                = 0x0,
    LINDSINK_FF                 = 0x1,
    LINDSINK_LIVE               = 0x2,
} lindsink_type_e;

typedef struct
{
    /**
     * 'sink_type' can set to be "mpegts/mp4/rtp/rtp_mpegts/rtsp/rtmp"
     * 'url' is used with 'sink_type'.
     * They can be set like this:
     *      |'sink_type'|'ip:port/name' or 'name' for file|
     *      |-----------+---------------------------------|
     *      |rtp_mpegts |rtp://192.168.3.118:12345        |
     *      |rtp        |rtp://192.168.3.118:12342/test   |
     *      |mp4        |/tmp/out.mp4                     |
     *      |mpegts     |/tmp/out.ts                      |
     */
    const char *    sink_type;
    const char *    ip;
    uint16_t        port;
    const char *    name;

    lindnet_type_e  protocol;
    int             mtu;
    int             payload_type;

    /**
     * audio parameters
     */
    int             have_audio;
    av_enc_type_t   aenc_type;
    int             channels;
    int             sample_rate;
    int             bits;
    int             period_size;
    int             bitrate_audio;
    uint8_t *       extradata_a;
    int             extradata_size_a;

    /**
     * video parameters
     */
    int             have_video;
    av_enc_type_t   venc_type;
    int             width;
    int             height;
    int             framerate;
    uint8_t *       extradata_v;
    int             extradata_size_v;

    int             apts_start_ms;
    int             vpts_start_ms;
} lindsink_config_t, rtpsink_config_t, ffsink_config_t, livesink_config_t;

typedef struct _lindsink_t
{
    void * priv;
    void (*close)(void * thiz);
    int  (*write)(void * thiz, av_frame2_t * p_frame);
} lindsink_t;

lindsink_t * lind_rtpsink_create(lindsink_config_t * p_config);
lindsink_t * lind_ffsink_create(lindsink_config_t * p_config);
lindsink_t * lind_livesink_create(lindsink_config_t * p_config);

lindsink_t * lindsink_create(lindsink_type_e type, lindsink_config_t * p_config);

#ifdef __cplusplus
}
#endif

#endif // __LIND_SINK_H__


